package top.superflow.flow.config.parse.impl

import top.superflow.core.utils.IdentifiableUtils
import top.superflow.exception.RequestUnsupportedException
import top.superflow.flow.config.dependency.DependencyManager
import top.superflow.flow.config.parse.Parser
import top.superflow.flow.config.process.ProcessConfig
import top.superflow.flow.runtime.process.ExtProcess


abstract class ProcessConfigParser extends Parser[ExtProcess]{

  def parse(original: Any): ExtProcess = {
    original match {
      case option: Some[_] => {
        parse(option)
      }
      case ct: ProcessConfig  => {
        val process = parseProcess(ct)
        IdentifiableUtils.copy(ct, process)

        val runtimeProcessProvider = DependencyManager.getInstance.getDependedProvider(ct.getDependencies)

        process.setProvider(runtimeProcessProvider)

        process
      }
      case _ => {
        throw new RequestUnsupportedException("Current config parser only supports config with type ")
      }
    }
  }

  protected def parseProcess(configType : ProcessConfig): ExtProcess

}